import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text("滚动控制")),
    body: const ScrollNotificationWidget(),
  )));
}

class ScrollNotificationWidget extends StatefulWidget {
  const ScrollNotificationWidget({Key? key}) : super(key: key);

  @override
  _ScrollNotificationWidgetState createState() => _ScrollNotificationWidgetState();
}

class _ScrollNotificationWidgetState extends State<ScrollNotificationWidget> {

  String _progress = "0%";

  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: NotificationListener<ScrollNotification>(
        onNotification: (ScrollNotification notification) {
          double progress = notification.metrics.pixels
              / notification.metrics.maxScrollExtent;
          setState(() => _progress = "${(progress * 100).toInt()}%");
          print("BottomEdge: ${notification.metrics.extentAfter == 0}");
          return false;
        },
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            ListView.builder(
              itemCount: 100,
              itemExtent: 50.0,
              itemBuilder: (context, index) => ListTile(title: Text("$index"),),
            ),
            CircleAvatar(
              radius: 30.0,
              backgroundColor: Colors.black54,
              child: Text(_progress),
            )
          ],
        ),
      ),
    );
  }
}
